-
Notifications
You must be signed in to change notification settings - Fork 0
feat: #11 add album detail view #57
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review
Two things to fix before merging:
1. Album links don't work on the server
The app is deployed under /project2/ (base: '/project2/' in vite.config.ts), but the new links go to /album/1 and /. On the VM they leave the app. The route check /^\/album\/(\d+)$/ also never matches /project2/album/1, so the detail page never shows up there. It only works locally if you open the dev server at the root.
Fix: Start links with import.meta.env.BASE_URL (e.g. ${import.meta.env.BASE_URL}album/${album.id}), and remove that prefix from window.location.pathname before running the regex. The same goes for the brand, "Discover" and "Back to discovery" links.
T19-Project-2/client/src/App.tsx
Lines 9 to 11 in d283a7f
| export default function App() { | |
| const detailMatch = /^\/album\/(\d+)$/.exec(window.location.pathname); | |
| const detailId = detailMatch?.[1]; |
T19-Project-2/client/src/components/AlbumCard.tsx
Lines 9 to 11 in d283a7f
| <h3 id={`album-${album.id}`}> | |
| <a href={`/album/${album.id}`}>{album.title}</a> | |
| </h3> |
T19-Project-2/client/src/pages/AlbumDetailPage.tsx
Lines 48 to 51 in d283a7f
| <main id="main" className="album-detail" tabIndex={-1}> | |
| <a className="back-link" href="/"> | |
| ← Back to discovery | |
| </a> |
2. The average rating is always empty
The page asks for averageRating, but the server has nothing that provides it: there is no resolver and no column on the album table. It always comes back null, so an album with reviews shows "Not yet rated · 3 reviews".
Fix: Add an averageRating resolver, for example a DataLoader next to reviewCountByAlbum that runs avg(review.rating) grouped by albumId.
T19-Project-2/server/src/resolvers.ts
Lines 177 to 188 in d283a7f
| Album: { | |
| artists: (album: AlbumRow, _: unknown, ctx: Context) => | |
| ctx.loaders.artistsByAlbum.load(album.id), | |
| genres: (album: AlbumRow, _: unknown, ctx: Context) => | |
| ctx.loaders.genresByAlbum.load(album.id), | |
| tracks: (album: AlbumRow, _: unknown, ctx: Context) => | |
| ctx.loaders.tracksByAlbum.load(album.id), | |
| reviewCount: (album: AlbumRow, _: unknown, ctx: Context) => | |
| ctx.loaders.reviewCountByAlbum.load(album.id), | |
| reviews: (album: AlbumRow, args: ReviewArgs, ctx: Context) => | |
| reviewsForAlbum(ctx.db, album.id, args), | |
| }, |
T19-Project-2/client/src/pages/AlbumDetailPage.tsx
Lines 85 to 89 in d283a7f
| <p className="muted"> | |
| {album.averageRating === null | |
| ? `Not yet rated · ${album.reviewCount} reviews` | |
| : `${album.averageRating.toFixed(1)} out of 5 · ${album.reviewCount} reviews`} | |
| </p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review
Ran the full gate suite on cd35ef9 locally: format:check, lint, typecheck, test and build all pass, and the test counts match the description exactly (51 client, 21 server). Code-splitting is confirmed - AlbumDetailPage-DF0LNxWt.js is its own 3.73 kB chunk with a separate CSS chunk.
The loader work is solid. All six loaders batch with inArray over parameterised queries, groupByAlbum returns one result per key in key order as DataLoader requires, and the loaders are created per request. Keyset paging over reviews on (createdAt, id) with limit + 1 is the right shape.
Findings
1. Search state is lost going to a detail page and back (medium-high)
AlbumCard links with href={${BASE_URL}album/${album.id}}, and both "Back to discovery" and the nav "Discover" link to import.meta.env.BASE_URL. So:
search "blue" -> click an album -> Back to discovery -> /project2/, no ?q=blue.
That undoes part of #19, whose whole point was that reload, back/forward and shared links keep the search. It also re-downloads the 427 kB main bundle on every album click, which is worth recording for #18.
Minimum fix: have the back link return to the search URL.
2. Album.reviews is a latent N+1 (medium)
reviewsForAlbum runs two queries per album - the page and a count(*). It is a relation field that does not go through a DataLoader, which is what the architecture rules are there to prevent.
Not reachable from the client today (searchAlbums only selects averageRating and reviewCount), so this is latent rather than active. Cheap fix: take totalCount from loaders.reviewCountByAlbum.load(albumId), which already exists and already batches. That drops one query per album and reuses the loader.
3. Star rating is not exposed to screen readers (medium)
In AlbumDetailPage.tsx:
<span aria-label={`${review.rating} out of 5 stars`}>{'★'.repeat(review.rating)}</span>A generic span has no accessible role, so aria-label is ignored by most screen readers. What gets announced is the repeated star glyphs, or nothing at all.
AlbumCard.tsx already does this correctly, with aria-hidden="true" on the glyph and the value in text. Same fix here: role="img" with the label, or hide the stars and add visually-hidden text. This is the star half of #17, and it is far easier to fix here than after the review UI lands on top of it.
4. averageRating is a live AVG() (low, follow-up)
averageRatingByAlbum runs avg(review.rating) GROUP BY album_id on every search page. #12 was revised to store album.average_rating with a trigger, partly because a live aggregate is not a stable sort key. Display is less sensitive than sorting, but once that column exists this loader should read it instead. Read-only here so there is no race risk, just worth recording so #12 and this do not both end up owning the number.
5. UTF-8 BOM in client/src/App.tsx (low)
First three bytes are ef bb bf. Prettier does not flag it and nothing is broken today, but it is the only BOM'd file in the repo and it will keep producing noisy diffs.
6. import.meta.env.BASE_URL in JSX props makes lint noisy (low)
Eight MetaProperty could not be resolved notices from jsx-ast-utils on every pnpm lint. Not a failure, but it is new noise on a clean gate.
On merging
Findings 1 and 3 are the two I would want addressed before this lands. 2, 4, 5 and 6 are fine as follow-ups.
|
Addendum: @evenkkl both of your points are already addressed in
Your review was on |
|
Correction to finding 5 above. I said There are four files with a UTF-8 BOM:
Only Downgrade it to background noise. If anyone wants to clean it up, it is a four-file change that belongs in its own commit and not in a feature branch. Apologies for the inaccuracy. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing the feedback from the previous reviews! 😊 The changes look good overall. I found two remaining issues that I think should be fixed before merging, and I've left inline comments on both. Otherwise, everything looks good!
|
One small UX suggestion: currently only the album title is clickable. It would feel more intuitive if clicking anywhere on the album card opened the detail page. Not a blocker, but worth considering! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good now! Thanks for addressing the feedback 😊
Closes #11
Summary
/album/:idroute and links album cards to it.album(id:)resolver and a paginatedAlbum.reviewsconnection.Verification
pnpm format:checkpnpm lintpnpm -r buildThe review create/update/delete UI is intentionally not included; that is delivered separately in #15 after this PR.